package md.mru.core.domains.administration;

import md.mru.core.domains.Folder;

import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import java.io.Serializable;

/**
 * @author sergiu.marin
 * @since 23.04.2014.
 */
@Embeddable
public class TreeFolderId implements Serializable {

    private static final long serialVersionUID = 7878173710896679877L;

    @ManyToOne(cascade = {})
    @JoinColumn(name = "tree_node_model_id")
    private TreeNodeModel treeNodeModel;

    //@Column(name = "folder_id", unique = true, nullable = false, precision = 10, scale = 0)
    @ManyToOne(cascade = {})
    @JoinColumn(name = "folder_id")
    private Folder folder;

    public TreeNodeModel getTreeNodeModel() {
        return treeNodeModel;
    }

    public void setTreeNodeModel(TreeNodeModel treeNodeModel) {
        this.treeNodeModel = treeNodeModel;
    }

    public Folder getFolder() {
        return folder;
    }

    public void setFolder(Folder folder) {
        this.folder = folder;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        TreeFolderId that = (TreeFolderId) o;

        return !(folder != null ? !folder.equals(that.folder) : that.folder != null) && !(treeNodeModel != null ? !treeNodeModel.equals(that.treeNodeModel) : that.treeNodeModel != null);

    }

    @Override
    public int hashCode() {
        int result = treeNodeModel != null ? treeNodeModel.hashCode() : 0;
        result = 31 * result + (folder != null ? folder.hashCode() : 0);
        return result;
    }
}
